package com.listen.common;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 原来用于加载配置文件——此类已废弃
 * 
 */
public class PropertiesLoad extends HttpServlet {

	private static final long serialVersionUID = 15000000000000000L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}
	
	public void init() throws ServletException {
        System.out.println("init t1 ... ");
        ServletContext application = this.getServletContext();
        String path = application.getRealPath("/WEB-INF/classes/daan.properties");
        Properties props=new Properties();//读取文件类型创建对象。  
        try {
			props.load(new FileInputStream(path));
			Object[] objs = props.keySet().toArray();
			for(int i=0;i<objs.length;i++){
				application.setAttribute(objs[i]+"", props.get(objs[i]));
			}
		} catch (FileNotFoundException e) {
			System.out.println("init t1 ... error");
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
    } 
}
